package com.ss.android.article.base.feature.subscribe.activity;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.TouchDelegate;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ss.android.account.model.BaseUser;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.subscribe.model.EntryItem;
import com.ss.android.common.lib.MobClickCombiner;

public class SubscribeButton extends RelativeLayout implements View.OnClickListener {
    TextView a;
    EntryItem b;
    private ProgressBar c;
    private Rect d;
    private boolean e;

    public SubscribeButton(Context arg2) {
        super(arg2);
        this.d = new Rect();
        this.e = false;
        this.a();
    }

    public SubscribeButton(Context arg2, AttributeSet arg3) {
        super(arg2, arg3);
        this.d = new Rect();
        this.e = false;
        this.a();
    }

    public SubscribeButton(Context arg2, AttributeSet arg3, int arg4) {
        super(arg2, arg3, arg4);
        this.d = new Rect();
        this.e = false;
        this.a();
    }

    private void a() {
        boolean v0 = android.support.design.a.m() == 2 ? true : false;
        this.e = v0;
    }

    static EntryItem a(SubscribeButton arg1) {
        return arg1.b;
    }

    final void a(boolean arg5, boolean arg6) {
        int v3 = 8;
        if (arg6) {
            this.a.setVisibility(v3);
            this.c.setVisibility(View.VISIBLE);
            this.setOnClickListener(null);
        } else {
            this.setOnClickListener(((View.OnClickListener) this));
            if (arg5) {
                if (!AppData.getInstance().D() || !this.e) {
                    this.a.setText(com.ss.android.article.browser.R.string.label_entry_unsubscribe);
                } else {
                    this.a.setText(com.ss.android.article.browser.R.string.label_entry_followed);
                }

                this.a.setSelected(true);
            } else {
                if (!AppData.getInstance().D() || !this.e) {
                    this.a.setText(com.ss.android.article.browser.R.string.label_entry_subscribe);
                } else {
                    this.a.setText(com.ss.android.article.browser.R.string.label_entry_follow);
                }

                this.a.setSelected(false);
            }

            this.a.setVisibility(View.VISIBLE);
            this.c.setVisibility(v3);
        }
    }

    public void onClick(View arg11) {
        boolean v0 = false;
        if (this.b != null) {
            boolean v9 = !this.b.isSubscribed() ? true : false;
            String v3 = v9 ? "subscribe" : "unsubscribe";
            MobClickCombiner.onEvent(this.getContext(), "subscription", v3, this.b.mId, 0);
            BaseUser v1 = new BaseUser(this.b.getUserId());
            v1.mNewSource = "39";
            com.ss.android.account.b.a.b.a(this.getContext()).a(v1, v9, null);
            if (!v9) {
                v0 = true;
            }

            this.a(v0, true);
        }
    }

    public void onFinishInflate() {
        super.onFinishInflate();
        this.a = this.findViewById(com.ss.android.article.browser.R.id.subscribe);
        this.c = this.findViewById(com.ss.android.article.browser.R.id.progress);
    }

    protected void onLayout(boolean arg4, int arg5, int arg6, int arg7, int arg8) {
        super.onLayout(arg4, arg5, arg6, arg7, arg8);
        if (arg4) {
            this.d.left = arg5;
            this.d.right = arg7 + 100;
            this.d.top = 0;
            this.d.bottom = arg8 + 100;
            TouchDelegate v1 = new TouchDelegate(this.d, ((View) this));
            if (View.class.isInstance(this.getParent())) {
                ((View) this.getParent()).setTouchDelegate(v1);
            }
        }
    }
}

